package com.ln.cmsln.controller.wei;

import com.ln.cmsln.pojo.entity.wei.Content;
import com.ln.cmsln.service.wei.ContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 魏存文
 * @since 2022-04-01
 */

@Api(tags = "内容管理")
@RestController
@RequestMapping("/api/content")
@CrossOrigin
public class ContentController {

    @Resource
    private ContentService contentService;

    @ApiOperation("内容管理全部数据")
    @GetMapping("/list")
    public Object list(){
        List<Content> list = contentService.list();
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("count", 0);
        map.put("data", list);
        return map;
    }

    @ApiOperation("新增内容")
    @PostMapping("/save")
    public boolean save(
            @ApiParam(value = "动态详情数据",required = true)
                    Content content
    ){
        return contentService.save(content);
    }

    @ApiOperation("修改内容")
    @PostMapping("/updateById/")
    public boolean updateById(Content content){
        return contentService.updateById(content);
    }

    @ApiOperation("删除内容")
    @PostMapping("/delete")
    public boolean delete(Long id){
        return contentService.removeById(id);
    }

}

